package link.luyu.plugin.brochain.web3.methods.response;

import java.math.BigInteger;
import java.util.List;
import org.web3j.utils.Numeric;

public class Votes {

    private String blockNumber;
    private String blockHash;
    private String params;
    private List<Vote> votes;

    public Votes() {}

    public Votes(String blockNumber, String blockHash, String params, List<Vote> votes) {
        this.blockNumber = blockNumber;
        this.blockHash = blockHash;
        this.params = params;
        this.votes = votes;
    }

    public BigInteger getBlockNumber() {
        return Numeric.decodeQuantity(blockNumber);
    }

    public String getBlockNumberRaw() {
        return blockNumber;
    }

    public void setBlockNumber(String blockNumber) {
        this.blockNumber = blockNumber;
    }

    public String getBlockHash() {
        return blockHash;
    }

    public void setBlockHash(String blockHash) {
        this.blockHash = blockHash;
    }

    public String getParams() {
        return params;
    }

    public void setParams(String params) {
        this.params = params;
    }

    public List<Vote> getVotes() {
        return votes;
    }

    public void setVotes(List<Vote> votes) {
        this.votes = votes;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Votes)) {
            return false;
        }

        Votes votes = (Votes) o;

        if (getBlockNumberRaw() != null
                ? !getBlockNumberRaw().equals(votes.getBlockNumberRaw())
                : votes.getBlockNumberRaw() != null) {
            return false;
        }
        if (getBlockHash() != null
                ? !getBlockHash().equals(votes.getBlockHash())
                : votes.getBlockHash() != null) {
            return false;
        }
        if (getParams() != null
                ? !getParams().equals(votes.getParams())
                : votes.getParams() != null) {
            return false;
        }
        return getVotes() != null ? getVotes().equals(votes.getVotes()) : votes.getVotes() == null;
    }

    @Override
    public int hashCode() {
        int result = getBlockNumberRaw() != null ? getBlockNumberRaw().hashCode() : 0;
        result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0);
        result = 31 * result + (getParams() != null ? getParams().hashCode() : 0);
        result = 31 * result + (getVotes() != null ? getVotes().hashCode() : 0);
        return result;
    }

    public static class Vote {

        private String nodeId;
        private String signature;

        public Vote() {}

        public Vote(String nodeId, String signature) {
            this.nodeId = nodeId;
            this.signature = signature;
        }

        public String getNodeId() {
            return nodeId;
        }

        public void setNodeId(String nodeId) {
            this.nodeId = nodeId;
        }

        public String getSignature() {
            return signature;
        }

        public void setSignature(String signature) {
            this.signature = signature;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (!(o instanceof Vote)) {
                return false;
            }

            Vote vote = (Vote) o;

            if (getNodeId() != null
                    ? !getNodeId().equals(vote.getNodeId())
                    : vote.getNodeId() != null) {
                return false;
            }
            return getSignature() != null
                    ? getSignature().equals(vote.getSignature())
                    : vote.getSignature() == null;
        }

        @Override
        public int hashCode() {
            int result = getNodeId() != null ? getNodeId().hashCode() : 0;
            result = 31 * result + (getSignature() != null ? getSignature().hashCode() : 0);
            return result;
        }
    }
}
